#include <stdio.h>
#include <unistd.h>

int g_val = 0;
int main()
{
    pid_t p = fork();  ///创建父子进程
    if(p < 0){
        perror("fork\n");
        return 0;
    }
    else if(p == 0){  //子进程
        g_val = 99;  //改变全局变量的值
        printf("i am clild %d, g_val is : %d, in %p\n", getpid(), g_val, &g_val);
    }
    else{
        sleep(2);
        printf("i am parent %d, g_val is : %d, in %p\n", getpid(), g_val, &g_val);
    }
    return 0;
}
